<?php

namespace apiend\modules\user\controllers;

use Yii;
use apiend\components\Controller;
use apiend\modules\user\models\ProfileForm;

/**
 * 个人资料相关功能
 * ProfileController for the `user` module
 */
class ProfileController extends Controller {

    /**
     * Declares the allowed HTTP verbs.
     * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs.
     * @return array the allowed HTTP verbs.
     */
    protected function verbs() {
        return [
            '*' => ['POST']
        ];
    }

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actionUpdate() {
        $model = new ProfileForm($this->token->user_id);
        if ($model->user->role_id) {
            $model->setScenario('educater');
        }
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::error('请提交要完善信息');
        }
        return $model->save();
    }

}
